

local sprotoparser = require "sprotoparser"


local M = {}

local types = [[
.package {	
	type 0 : integer
	session 1 : integer
}

]]

local c2s   = [[]]
local s2c   = [[]]

-- 拼接所有协议
function M.init(cfg)

	if not cfg then 
		return false 
	end 

	local fd = assert(io.open(cfg,"rb"))
	
	while true do 

		local read_line = fd:read("*line")

		if not read_line then 
			break 
		end 

		if read_line ~= "" then 

				if not string.find(read_line,"#") then 

					local _,_,value = string.find(read_line,"%s*(.-)%s*$")

					if value then 
						
						local proto = require(value) 
						types = types .. proto.types
						c2s = c2s .. proto.c2s 
						s2c = s2c .. proto.s2c 
						print("已加载" .. value .. "协议" )	
					end 
				end 
		end 
	end 

	fd:close()

	return true 
end 

-- 解析协议
function M.parse()

	M.types = sprotoparser.parse(types)
	M.c2s   = sprotoparser.parse(types .. c2s)
	M.s2c   = sprotoparser.parse(types .. s2c)
end 


return M



